package com.hyx.java.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyx.java.base.PageBean;
import com.hyx.java.dto.HyxTaskSearchReq;
import com.hyx.java.dto.HyxUserSearchReq;
import com.hyx.java.entity.HyxTask;
import com.hyx.java.entity.HyxUser;
import com.hyx.java.mapper.HyxTaskMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class HyxTaskService {

    @Autowired
    private HyxTaskMapper taskMapper;

    public PageBean userPage(HyxTaskSearchReq search) {
        PageBean pageBean = new PageBean(search.getCurPage(), search.getPageSize());
        LambdaQueryWrapper<HyxTask> wrapper = new QueryWrapper<HyxTask>().lambda()
            .eq(search.getId() != null, HyxTask::getId, search.getId())
            .eq(search.getStatus() != null, HyxTask::getStatus, search.getStatus())
            .eq(StringUtils.isNotBlank(search.getTestName()), HyxTask::getTestName, search.getTestName())
            .ge(StringUtils.isNotBlank(search.getTestDate()), HyxTask::getTestDate, search.getTestDate() + " 00:00:00");
        wrapper.orderByDesc(HyxTask::getId);
        IPage<HyxTask> taskPage = taskMapper.selectPage(
            new Page<>(pageBean.getCurPage(), pageBean.getPageSize()),wrapper);
        pageBean.setRecords(taskPage.getRecords());
        pageBean.setPages(taskPage.getPages());
        pageBean.setTotal(taskPage.getTotal());
        return pageBean;
    }
}
